
cmake_minimum_required(VERSION 3.20)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_C_STANDARD 17)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)

project(cmake-install)

set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/install)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmakes)
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/install/modules)
#SET(MyModule_DIR "${CMAKE_CURRENT_SOURCE_DIR}/install/modules/lib/cmake/MyModule")
#SET(MyModule_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/install/modules/lib/cmake/MyModule)

set(OUTPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/output)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${OUTPUT_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${OUTPUT_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_DIR})

add_subdirectory(modules)
add_subdirectory(libShared)


add_executable(main main.cpp)
set_target_properties(main PROPERTIES DEBUG_POSTFIX "d")
add_dependencies(main libShared MyModuleInstall)

find_package(MyLibShared MODULE)
if (MyLibShared_FOUND)
    target_link_libraries(main PUBLIC MyLibShared)
    target_compile_definitions(main PRIVATE USE_SHARED_LIB)
else ()
    message(WARNING "Please build LibShared First!!")
endif ()

message(STATUS "MyModule_DIR：${MyModule_DIR}")

find_package(MyModule CONFIG
#        PATHS ${CMAKE_CURRENT_SOURCE_DIR}/install/modules
#        HINTS ${CMAKE_CURRENT_SOURCE_DIR}/install/modules
)
if (MyModule_FOUND)
    target_link_libraries(main PUBLIC MyModule)
    target_compile_definitions(main PRIVATE USE_MY_MODULE)
else ()
    message(WARNING "Please build MyModule First!!")
endif ()
